package com.ruoyi.common.core.utils.aliyun;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.alimt20181012.models.GetImageTranslateResponse;
import com.aliyun.alimt20181012.models.GetImageTranslateResponseBody;
import com.aliyun.alimt20181012.models.GetImageTranslateResponseBody.GetImageTranslateResponseBodyData;
import com.aliyun.tea.TeaException;

public class PictureEditorUtils {

	public static Object pictureEditor(String url) {
		// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和
		// ALIBABA_CLOUD_ACCESS_KEY_SECRET。
		// 工程代码泄露可能会导致 AccessKey 泄露，并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey
		// 的方式进行调用，仅供参考，建议使用更安全的 STS
		// 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378657.html
		com.aliyun.alimt20181012.Client client = ClientUtils.createClient();
		com.aliyun.alimt20181012.models.GetImageTranslateRequest getImageTranslateRequest = new com.aliyun.alimt20181012.models.GetImageTranslateRequest();
		getImageTranslateRequest.setExtra(
				"{\"without_text\":\"false\",\"have_ocr\":\"false\",\"have_psd\":\"true\",\"ignoreEntityRecongizationMarker\":\"false\"}");
		getImageTranslateRequest.setUrl(url);
		getImageTranslateRequest.setSourceLanguage("zh");
		getImageTranslateRequest.setTargetLanguage("en");
		com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
		try {
			// 复制代码运行请自行打印 API 的返回值
			GetImageTranslateResponse imageTranslateWithOptions = client
					.getImageTranslateWithOptions(getImageTranslateRequest, runtime);
			GetImageTranslateResponseBody body = imageTranslateWithOptions.getBody();
			GetImageTranslateResponseBodyData data = body.getData();
			String pictureEditor = data.getPictureEditor();
			Object parse = JSONObject.parse(pictureEditor);
			return parse;
		} catch (TeaException error) {
			// 如有需要，请打印 error
			com.aliyun.teautil.Common.assertAsString(error.message);
		} catch (Exception _error) {
			TeaException error = new TeaException(_error.getMessage(), _error);
			// 如有需要，请打印 error
			com.aliyun.teautil.Common.assertAsString(error.message);
		}
		return null;
	}

}
